//
//  JHSSicknessDevideController.m
//  病例管理
//
//  Created by chenWei on 2017/3/24.
//  Copyright © 2017年 陈伟. All rights reserved.
//

#import "JHSSicknessDevideController.h"
#import "JHSSickDevideModel.h"


@interface JHSSicknessDevideController ()

@property (nonatomic, strong) NSMutableArray *modelArr;






@end

@implementation JHSSicknessDevideController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadNetData];
    
    _modelArr = [NSMutableArray array];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
    
    
    
}


#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return _iteger == 0 ? 0 : _modelArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    NSDictionary *modelDic = _modelArr[indexPath.row];
    
    cell.textLabel.text = modelDic[@"ci3_name"];
    
    
    
    return cell;
}


#pragma mark - 代理方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //动画取消选中
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    //把模型数据返回
    
    if ([self.delegate respondsToSelector:@selector(sicknessDevideController:withNSMutableArray: withNSIndexPath:)]) {
        
        [self.delegate sicknessDevideController:self withNSMutableArray:_modelArr withNSIndexPath:indexPath];
        
    }
    
    //pop 当前控制器
    [self.navigationController popViewControllerAnimated:YES];
    
}



#pragma mark - 加载网络数据

- (void)loadNetData
{
//    NSLog(@"%@",[NSThread currentThread]);
    
    NSString *url = @"http://iosapi.itcast.cn/doctor/searchCI3List.json.php";

//    NSLog(@"$$$$$$$$$$    %zd",_iteger);
    
    
    NSDictionary *parameters = @{@"page":@1,@"page_size":@15,@"ci1_id":@(_iteger),@"keyword":@""};
    
    [JHSSickDevideModel devideNetDataWithURL:url withParameters: parameters withSuccessBlock:^(id responceBoby) {
        
//        NSLog(@"=======%@",responceBoby);
        
        
        _modelArr = responceBoby;
        
        [self.tableView reloadData];
        
    } withFailureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
    }];
    
    
    
    
    
    
}









@end
